<template>
  <view class="company-job">
    <view class="company" @click="toCompany">
      <image :src="item.companyLogo || defaultCompanylogo" alt="" mode="aspectFill" class="logo" />
      <view class="company-info">
        <view class="title u-line-1">{{item.companyName}}</view>
        <view class="address">{{item.companyDq || ''}}</view>
        <view class="position-info">{{item.positionInfo || ''}}</view>
      </view>
      <view class="check">查看职位 <u-icon name="arrow-right" color="#BFBFBF" class="u-m-l-16"></u-icon> </view>
    </view>
    <view class="job">
        <view class="job-item" v-for="(job, index) in jobs" :key="index" >
          <text class="job-name u-line-1" @click="toJobDetail(job)">{{job.jtzw}}</text>
          <template v-if="isShowBtn">
            <view v-if="job.deliverStatus == 1" class="btn btn-operate status-1">
              <template>已投递</template>
            </view>
            <view v-else-if="job.isStop == 1" class="btn btn-operate status-1">
              <template>已停招</template>
            </view>
            <view v-else-if="job.deliverStatus == 0 " class="btn btn-operate status-0" @click="handleDeliver(job, index)">
              <template>投递</template>
            </view>
          </template>
        </view>
    </view>
  </view>
</template>

<script>
import Empty from '@/components/Empty.vue'

export default {
  components: {
    Empty,
  },
  props: {
    item: {
      type: Object,
      default: () => ({}),
    },
    personId: {
      type: [String, Number],
      default: ''
    },
    belongType: [String, Number],
    activityId: [String, Number],
  },
  data() {
    return {
      emptyImg: this.$imgBaseSelf + 'common/empty.png',
      defaultCompanylogo: this.$imgBase + "company/logo.jpg",
    }
  },
  computed: {
    jobs() {
      if (this.belongType === 4) {
        return this.item.jobs;
      } else {
        return this.item.zpArr;
      }
    },
    isShowBtn() {
      if (this.activityId == '2031721125699544') {
        const limitTime = new Date('2024/10/12').getTime();
        const nowTime = new Date().getTime();
        return (nowTime >= limitTime)
      } else {
        return true;
      }
    }
  },
  methods: {
    toJobDetail(item) {
      if(item.isStop == 1) {
        return;
      }
      uni.navigateTo({
        url: '/pagesSub/public/jobDetail/index?jobId=' + (item.id || item.jobId) + '&activityId='+this.activityId
      });
    },
    toCompany() {
      uni.navigateTo({
        url: '/pagesSub/public/companyDetail/index?tab=1&companyId=' + this.item.companyId + '&activityId='+this.activityId
      });
    },
    handleDeliver(job, index) {
      this.$emit('deliver', {company: this.item, job, index});
    }
  }
}
</script>

<style lang="scss" scoped>
.company-job {
  margin: 16rpx 32rpx;
  padding: 32rpx;
  background-color: #FFF;
  border-radius: 10rpx;
  box-shadow: 0 24rpx 40rpx -23rpx #eee;
  
  .company {
    display: flex;
    margin-bottom: 20rpx;
  }
  .company-info {
    width: 1rpx;
    flex-grow: 1;
    .title {
      margin-bottom: 12rpx;
      color: #333333;
      font-size: 28rpx;
      font-weight: 500;
    }
    .address {
      color: #999999;
      font-size: 26rpx;
    }

    .position-info {
      margin-top: 6rpx;
      color: #F75A3E;
      font-size: 30rpx;
    }
  }
  .check {
    flex-shrink: 0;
    margin-left: 50rpx;
    font-size: 24rpx;
    color: #888888;
  }
  .logo {
    margin-right: 20rpx;
    width: 86rpx;
    height: 86rpx;
    border-radius: 12rpx;
  }
  .job-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin: 18rpx 0;
    font-size: 28rpx;
    color: #333333;
    &:last-child {
      margin: 0;
    }

    .btn {
      flex-shrink: 0;
      margin-left: 20rpx;
      height: 44rpx;
      padding: 0rpx 14rpx;
      font-size: 20rpx;
      line-height: 38rpx;
      border-radius: 22rpx;
    }
    
    .status{
      &-0 {
        border: 2rpx solid #F75A3E;
        color: #F75A3E;
      }
      &-1 {
        border: 2rpx solid #D8D8D8;
        color: #999999;
      }
    }
  }
}
</style>